AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
 
function ENT:Think()
	if (ValidEntity(self.dt.Owner)==false || ValidEntity(self.PipeExit)==false) then
		self.Entity:Remove()
	end
end

function ENT:OnRemove()
	if(ValidEntity(self.PipeExit)) then
		self.PipeExit:Remove()
	end
end

function ENT:Touch(item)
	local itemclass = item:GetClass()
	local onitemtable = table.HasValue(pipeacceptable, itemclass)
	
	if(itemclass == "sign" || itemclass == "spawned_weapon" || onitemtable || string.sub(itemclass, 1, 5) == "item_" || string.sub(itemclass, 1, 5) == "drug_" ) then		
		if(item.Time == nil) then
			item.Time = CurTime() - 10
		end
		if (item.Time < CurTime()-5) then
			
			ErrorNoHalt(util.QuickTrace(self.PipeExit:GetPos(), self.PipeExit:GetUp() * 20, { self.PipeExit }).Hit)
			
			if(onitemtable && util.QuickTrace(self.PipeExit:GetPos(), self.PipeExit:GetUp() * 20, { self.PipeExit }).Hit == true) then
				--Grenade bounces back and explodes in the fucker's face
			else
				item:SetAngles(self.Entity:GetAngles())
				item:SetVelocity(Vector(0,0,0))
				item:SetPos(self.PipeExit:GetPos() + self.PipeExit:GetUp() * 20)
				item.Time = CurTime()
			end
		
		end
	end
end